package com.openbravo.pos.panels;

import com.openbravo.basic.BasicException;
import com.openbravo.data.gui.JCounter;
import com.openbravo.data.gui.JLabelDirty;
import com.openbravo.data.gui.JListNavigator;
import com.openbravo.data.gui.JNavigator;
import com.openbravo.data.gui.JSaver;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.ComparatorCreator;
import com.openbravo.data.loader.Vectorer;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecord;
import com.openbravo.data.user.ListProvider;
import com.openbravo.data.user.SaveProvider;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.BeanFactoryApp;
import com.openbravo.pos.forms.BeanFactoryException;
import com.openbravo.pos.forms.JPanelView;
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

public abstract class JPanelTable extends JPanel
  implements JPanelView, BeanFactoryApp
{
  protected BrowsableEditableData bd;
  protected DirtyManager dirty;
  protected AppView app;
  private JPanel container;
  private JPanel toolbar;

  public JPanelTable()
  {
    initComponents();
  }

  public void init(AppView paramAppView)
    throws BeanFactoryException
  {
    this.app = paramAppView;
    this.dirty = new DirtyManager();
    this.bd = null;
    init();
  }

  public Object getBean()
  {
    return this;
  }

  protected void startNavigation()
  {
    if (this.bd == null)
    {
      this.bd = new BrowsableEditableData(getListProvider(), getSaveProvider(), getEditor(), this.dirty);
      Object localObject = getFilter();
      if (localObject != null)
      {
        ((Component)localObject).applyComponentOrientation(getComponentOrientation());
        add((Component)localObject, "North");
      }
      try {//ati
    	  localObject = getEditor().getComponent();
	} catch (Exception e) {
		e.printStackTrace();
	}
    
      if (localObject != null)
      {
        ((Component)localObject).applyComponentOrientation(getComponentOrientation());
        this.container.add((Component)localObject, "Center");
      }
      ListCellRenderer localListCellRenderer = getListCellRenderer();
      if (localListCellRenderer != null)
      {
        JListNavigator localJListNavigator = new JListNavigator(this.bd);
        localJListNavigator.applyComponentOrientation(getComponentOrientation());
        if (localListCellRenderer != null)
          localJListNavigator.setCellRenderer(localListCellRenderer);
        this.container.add(localJListNavigator, "Before");
      }
      localObject = getToolbarExtras();
      if (localObject != null)
      {
        ((Component)localObject).applyComponentOrientation(getComponentOrientation());
        this.toolbar.add((Component)localObject);
      }
      localObject = new JLabelDirty(this.dirty);
      ((Component)localObject).applyComponentOrientation(getComponentOrientation());
      this.toolbar.add((Component)localObject);
      localObject = new JCounter(this.bd);
      ((Component)localObject).applyComponentOrientation(getComponentOrientation());
      this.toolbar.add((Component)localObject);
      localObject = new JNavigator(this.bd, getVectorer(), getComparatorCreator());
      ((Component)localObject).applyComponentOrientation(getComponentOrientation());
      this.toolbar.add((Component)localObject);
      localObject = new JSaver(this.bd);
      ((Component)localObject).applyComponentOrientation(getComponentOrientation());
      this.toolbar.add((Component)localObject);
    }
  }

  public Component getToolbarExtras()
  {
    return null;
  }

  public Component getFilter()
  {
    return null;
  }

  protected abstract void init();

  public abstract EditorRecord getEditor();

  public abstract ListProvider getListProvider();

  public abstract SaveProvider getSaveProvider();

  public Vectorer getVectorer()
  {
    return null;
  }

  public ComparatorCreator getComparatorCreator()
  {
    return null;
  }

  public ListCellRenderer getListCellRenderer()
  {
    return null;
  }

  public JComponent getComponent()
  {
    return this;
  }

  public void activate()
    throws BasicException
  {
    startNavigation();
    this.bd.actionLoad();
  }

  public boolean deactivate()
  {
	  
    try
    {
      return this.bd.actionClosingForm(this);
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, AppLocal.getIntString("message.CannotMove"), localBasicException);
      localMessageInf.show(this);
    }
    return false;
  }

  private void initComponents()
  {
    this.container = new JPanel();
    this.toolbar = new JPanel();
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BorderLayout());
    this.container.setLayout(new BorderLayout());
    this.container.add(this.toolbar, "North");
    add(this.container, "Center");
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.panels.JPanelTable
 * JD-Core Version:    0.6.0
 */